/*
 * @Author: szx
 * @Date: 2022-04-05 13:11:00
 * @LastEditTime: 2022-04-05 13:16:22
 * @Description:
 * @FilePath: \leetcode\剑指offerII\033\033.js
 */
/**
 * @param {string[]} strs
 * @return {string[][]}
 */

var groupAnagrams = function (strs) {
    let obj = {};
    strs.forEach((word) => {
        // 将每个字符串分割成数组进行排序，然后再变成字符串
        const key = word.split('').sort().toString();

        // 对每个key都创建一个数组，用来保存key相同的字符串
        if (!(key in obj)) {
            obj[key] = [];
        }

        obj[key].push(word);
    });

    return Object.values(obj);
};
